Here is a patched KMotionCNC compatible with Release V4.33q that includes three new KMotionCNC "automation" commands:
ON_COMMAND(ID_ReloadGCodeFile, OnReloadGCodeFile)
ON_COMMAND(ID_OpenGCodeFile, OnOpenGCodeFile)
ON_WM_COPYDATA()
The Binaries and changed source files are here:
Here is the related code added to KMotionCNC:
void CKMotionCNCDlg::OnReloadGCodeFile()
{
LoadFile(m_Thread,true);
CurrentDirectory = ExtractDirectory(FileNames[m_Thread]);
}
void CKMotionCNCDlg::OnOpenGCodeFile()
{
FileNames[m_Thread] = InterprocessString;
LoadFile(m_Thread,true);
CurrentDirectory = ExtractDirectory(FileNames[m_Thread]);
}
BOOL CKMotionCNCDlg::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct)
{
InterprocessString = (LPCTSTR)pCopyDataStruct->lpData;
return TRUE;
}
We added an example Button in the SimpleFormsCS C# example to demonstrate the functionality. See the top right button:
It loads the fixed file "Dynomotion.ngc" from the GCode Programs directory.
The related code from Form1.cs is:
private void TestOpenKMotionCNC_click(object sender, EventArgs e)
{
String message = MainPath + "\\GCode Programs\\Dynomotion.ngc";
COPYDATASTRUCT cds;
cds.dwData = 0;
cds.lpData = (int)Marshal.StringToHGlobalAnsi(message);
cds.cbData = message.Length+1;
IntPtr KMotionCNCWindow = FindWindow("KMotionCNC", null);
SendMessage(KMotionCNCWindow, (int)WM_COPYDATA, 0, ref cds);
Marshal.FreeHGlobal((IntPtr)cds.lpData);
uint WM_COMMAND = 0x0111;
int ID_OpenGCodeFile = 33018;
SendMessage(KMotionCNCWindow, (int)WM_COMMAND, ID_OpenGCodeFile, 0);
}
Let us know if you have any issues.
Regards
TK
Group: DynoMotion |
Message: 12307 |
From: Shannon Davenport |
Date: 9/24/2015 |
Subject: Re: Opening Gcode files [1 Attachment] |
Hi Tom, Sorry for my lack of understanding here; but how do I implement this new functionality? I downloaded the files and am running the new KMotionCNC. I looked at the source code and it looks like the just opened file name should be here: C:\KMotion433q\KMotion\Data\GFilescnc.txt. But I don't see it until KmotionCNC is closed. Thanks, Shannon | |